import { BasicColumn, FormSchema } from '@apps/antd-admin/src/components/table';
import { airportList } from '@apps/ant-bus/src/views/business/airport/data/api';
import { existByVipCardNo, getTiYanVipcardList } from './api';
import { weChatList } from '@apps/ant-bus/src/views/business/platformManage/wechat/data/api';
import { RenderType } from '@pkg/setting';

export const columns: BasicColumn[] = [
  {
    title: '当前归属账号',
    dataIndex: 'mainAccount',
    width: 120,
  },
  {
    title: '原先归属账号',
    dataIndex: 'oldMainAccount',
    width: 120,
  },
  {
    title: '原先归属会员卡',
    dataIndex: 'belongVipCardNo',
    width: 150,
  },
  {
    title: '会员姓名',
    dataIndex: 'userName',
    width: 120,
  },
  {
    title: '手机号',
    dataIndex: 'mobile',
    width: 120,
  },
  {
    title: '名称',
    dataIndex: 'goodsName',
    width: 180,
  },
  {
    title: '券号',
    dataIndex: 'vipCardNo',
    width: 150,
  },
  {
    title: '状态',
    dataIndex: 'vipCardState',
    width: 120,
    dictData: [
      { label: '待激活', value: 0 },
      { label: '正常', value: 1 },
      { label: '已过期', value: 2 },
      { label: '未开通', value: 3 },
      { label: '未通过', value: 4 },
      { label: '冻结', value: 5 },
      { label: '退卡中', value: 6 },
      { label: '已退卡', value: 7 },
      { label: '已转卡', value: 8 },
      { label: '已转赠', value: 9 },
      { label: '冻结（延时开通）', value: 10 },
    ],
    renderType: RenderType.DICT,
  },
  {
    title: '赠送来源',
    dataIndex: 'optUserType',
    width: 130,
    dictData: [
      { label: '销售端赠送', value: 1, color: '#ad5419' },
      { label: '后台赠送', value: 2, color: '#095ad5' },
    ],
    renderType: RenderType.DICT,
  },
  {
    title: '赠送人',
    dataIndex: 'optUserName',
    width: 120,
  },
  {
    title: '赠送地',
    dataIndex: 'airportName',
    width: 150,
  },
  {
    title: '赠送日期',
    dataIndex: 'buyDate',
    width: 120,
  },
  {
    title: '支付金额',
    dataIndex: 'payAmount',
    width: 120,
  },
  {
    title: '贵宾厅服务有效期',
    dataIndex: 'viproomDate',
    width: 130,
  },
  {
    title: '贵宾厅服务状态',
    dataIndex: 'vipServerIsExpre',
    width: 130,
    dictData: [
      { label: '已过期', value: true, color: '#f60606' },
      { label: '未过期', value: false, color: '#5ade70' },
    ],
    renderType: RenderType.DICT,
  },
  {
    title: '贵宾厅服务次数',
    dataIndex: 'serverValue',
    width: 120,
  },
  {
    title: '贵宾厅剩余次数',
    dataIndex: 'restValue',
    width: 130,
  },
  {
    title: '创建时间',
    dataIndex: 'createTime',
    width: 150,
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'oldMainAccount',
    label: '原先归属账号',
    component: 'Input',
    colProps: { span: 5 },
  },
  {
    field: 'userName',
    label: '姓名',
    component: 'Input',
    colProps: { span: 5 },
  },
  {
    field: 'mobile',
    label: '手机号',
    component: 'Input',
    colProps: { span: 5 },
  },
  {
    field: 'vipCardNo',
    label: '卡号',
    component: 'Input',
    colProps: { span: 5 },
  },
  {
    field: 'optUserType',
    label: '赠送来源',
    labelWidth: 500,
    component: 'Select',
    colProps: { span: 4 },
    componentProps: {
      options: [
        { label: '销售端赠送', value: 1 },
        { label: '后台赠送', value: 2 },
      ],
    },
  },
  {
    field: 'optUserName',
    label: '赠送人',
    labelWidth: 500,
    component: 'Input',
    colProps: { span: 4 },
  },
  {
    field: 'airportId',
    label: '开卡地',
    component: 'ApiSelect',
    colProps: { span: 4 },
    componentProps: {
      api: airportList,
      params: { handlerName: 'busAirportRoleListHandler' },
      labelField: 'airportName',
      valueField: 'airportId',
      immediate: true,
      showSearch: true,
    },
  },
  {
    field: 'vipCardState',
    label: '状态',
    component: 'Select',
    colProps: { span: 5 },
    componentProps: {
      options: [
        { label: '待激活', value: 0 },
        { label: '正常', value: 1 },
        { label: '已过期', value: 2 },
        { label: '未开通', value: 3 },
        { label: '未通过', value: 4 },
        { label: '冻结', value: 5 },
        { label: '退卡中', value: 6 },
        { label: '已退卡', value: 7 },
        { label: '已转卡', value: 8 },
        { label: '已转赠', value: 9 },
        { label: '冻结（延时开通）', value: 10 },
      ],
    },
  },
  {
    field: 'startDate',
    label: '开始日期',
    component: 'DatePicker',
    colProps: { span: 5 },
    componentProps: {
      valueFormat: 'YYYY-MM-DD',
      format: 'YYYY-MM-DD',
    },
  },
  {
    field: 'endDate',
    label: '结束日期',
    component: 'DatePicker',
    colProps: { span: 5 },
    componentProps: {
      valueFormat: 'YYYY-MM-DD',
      format: 'YYYY-MM-DD',
    },
  },
];

export const formSchema: FormSchema[] = [
  {
    label: '产品',
    field: 'goodsId',
    component: 'ApiSelect',
    required: true,
    componentProps: {
      api: getTiYanVipcardList,
      labelField: 'goodsName',
      valueField: 'goodsId',
      immediate: true,
      showSearch: true,
    },
  },
  {
    label: '关联会员卡号',
    field: 'belongVipCardNo',
    component: 'Input',
    required: false,
  },
  {
    label: '数量',
    field: 'goodsNum',
    defaultValue: 1,
    component: 'InputNumber',
    required: true,
  },
  {
    label: '姓名',
    field: 'userName',
    component: 'Input',
    required: true,
  },
  {
    label: '手机号',
    field: 'userMobile',
    component: 'Input',
    required: true,
    rules: [
      { required: true, message: '请输入手机号' },
      { pattern: /^1[3456789]\d{9}$/, message: '手机号码格式错误！' },
    ],
  },
  {
    label: '所属公众号',
    field: 'weChatId',
    component: 'ApiSelect',
    required: true,
    componentProps: {
      api: weChatList,
      labelField: 'weChatName',
      valueField: 'weChatId',
      immediate: true,
    },
  },
];
